package com.lglbc.filter;

import org.springframework.cloud.gateway.filter.GatewayFilter;
import org.springframework.cloud.gateway.filter.factory.AbstractGatewayFilterFactory;
import org.springframework.stereotype.Service;
import reactor.core.publisher.Mono;

/**
 * @Author 乐哥聊编程
 * @Doc 关注公众号"乐哥聊编程"获取文档和源码
 * @Date 2023/6/18
 * @Description
 */
@Service
public class LglbcGatewayFilterFactory extends AbstractGatewayFilterFactory<LglbcGatewayFilterFactory.LglbcConfig> {
    @Override
    public GatewayFilter apply(LglbcConfig config) {
        return (((exchange, chain) -> {
            System.out.println("LglbcGatewayFilterFactory 请求之前调用 "+config.getName());
         return chain.filter(exchange).then(Mono.fromRunnable(()->{
                 System.out.println("LglbcGatewayFilterFactory 请求之后调用 "+config.getName());
         }));
        }));
    }
    public static class LglbcConfig {
        private String name;

        public String getName() {
            return name;
        }

        public void setName(String name) {
            this.name = name;
        }
    }

    public LglbcGatewayFilterFactory() {
        super(LglbcConfig.class);
    }
}